package uit.shoeshop.model;

import uit.shoeshop.dto.CategoryDTO;
import uit.shoeshop.dao.CategoryDAO;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

public class SidebarModel {
	public SidebarModel(){
		
	}
	
	public ArrayList<CategoryDTO> getAllParentCategory() throws SQLException{
		ArrayList<CategoryDTO> category = new ArrayList<CategoryDTO>();

		CategoryDAO tblCategory = new CategoryDAO();
		
		/*
		 * Lay tat ca cac category cha
		 */
		category = tblCategory.getCategory(0, 1);
		
		tblCategory = null;
		return category;
	}

	public HashMap<Integer, ArrayList<CategoryDTO>> getAllChildCategory(ArrayList<CategoryDTO> parentCate) throws SQLException{
		HashMap<Integer, ArrayList<CategoryDTO>> category = new HashMap<Integer, ArrayList<CategoryDTO>>();
		CategoryDAO tblCategory = new CategoryDAO();		
		int cateId = 0 ;
		ArrayList<CategoryDTO> temp;
		
		for (CategoryDTO cate : parentCate) {
			cateId = cate.getCategory_id();
			temp = tblCategory.getCategory(cateId, 1);
			if(temp.size() > 0){
				category.put(cateId, temp);
			}
		}
		
		temp = null;
		tblCategory = null;
		return category;
	}	
}
